﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Project.Admin
{
    public partial class CreateTellers : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            DataPOFDataContext db = new DataPOFDataContext();
            string acc = (from x in db.AccountLogins where x.Username == Session["username"].ToString() select x.FullName).FirstOrDefault();
            Label1.Text = acc;
            int ID = (from x in db.AccountLogins select x.Id).Count();
            TextBox1.Text = Convert.ToString(ID + 1);
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            Session["username"] = null;
            Response.Cache.SetNoStore();
            Response.CacheControl = "no-cache";
            Response.Redirect("../Home/Login.aspx");
        }

        protected void Button4_Click(object sender, EventArgs e)
        {
            DataPOFDataContext data = new DataPOFDataContext();

            // Add new Customer to data
            if (TextBox6.Text == "")
            {
                Label3.Text = "Input Fullname!";
                Label4.Text = "";
                Label5.Text = "";
                Label6.Text = "";
                Label7.Text = "";
            }
            else
                if (TextBox7.Text == "")
                {
                    Label4.Text = "Input UserName!"; 
                    Label3.Text = "";
                    Label5.Text = "";
                    Label6.Text = "";
                    Label7.Text = "";
                }
                else if (TextBox2.Text == "")
                {
                    Label5.Text = "Input Password!"; 
                    Label3.Text = "";
                    Label4.Text = "";
                    Label6.Text = "";
                    Label7.Text = "";
                }
                else if (TextBox4.Text == "")
                {
                    Label6.Text = "Input Email!";
                    Label3.Text = "";
                    Label4.Text = "";
                    Label5.Text = "";
                    Label7.Text = "";
                }
                else if (TextBox5.Text == "")
                {
                    Label7.Text = "Input Teller No!";
                    Label3.Text = "";
                    Label4.Text = "";
                    Label5.Text = "";
                    Label6.Text = "";
                }
                else
                {

                    AccountLogin AccountLogin = new AccountLogin();
                    AccountLogin.Id = Convert.ToInt32(TextBox1.Text);
                    AccountLogin.FullName = TextBox6.Text;
                    AccountLogin.Username = TextBox7.Text;
                    AccountLogin.Password = TextBox2.Text;
                    AccountLogin.Email = TextBox4.Text;
                    AccountLogin.Teller_No = TextBox5.Text;
                    AccountLogin.Roll = DropDownList3.SelectedItem.ToString();
                    AccountLogin.LocationID = (from x in data.Locations where x.Location1 == DropDownList2.SelectedValue.ToString() select x.ID).FirstOrDefault();
                    try
                    {

                        data.AccountLogins.InsertOnSubmit(AccountLogin);

                    }

                    catch (Exception ex)
                    {

                        //MessageBox.Show(ex.Message);

                    }

                    finally
                    {

                        // Submit to data

                        data.SubmitChanges();

                    }
                    Label2.Text = "Register successfully !";
                    Response.Redirect("../Admin/CreateTellers.aspx");
                }
        }
    }
}